package interpreter;

import java.awt.geom.Line2D;

import composite.ObjectItem;

/**
 * Composite pattern and interpreter and template pattern mix.
 * Defines BasicObject, this object can not hold any other objects.
 */
@SuppressWarnings("serial")
public class PrimitiveLine extends PrimitiveAbstract implements ObjectItem{
	int x1, y1, x2, y2;
	
	/**
	 * Line primitive constructor
	 */
	public PrimitiveLine(int x1, int y1, int x2, int y2){
		type = "line";
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
		
		//Initial position
		posX=0;
		posY=0;
		
		createShape();
	}
	
	public void scale(double scaleX , double scaleY){
    	if(scaleX <= 0.1)
    		scaleX = 0.1;
    	if(scaleY <= 0.1)
    		scaleY = 0.1;
    	
    	if(scaleX > 20)
    		scaleX = 20;
    	if(scaleY > 20)
    		scaleY = 20;
    	
    	this.scaleX = scaleX;
    	this.scaleY = scaleY;
		
		createShape();
	}
	
	protected void createShape(){
		shape = new Line2D.Double(x1*scaleX+posX, y1 * scaleY + posY , x2 * scaleX + posX, y2 * scaleY + posY);		
	}
		
	/**
	 * Create a copy of the primitive shape, to avoid references issues for not base(int etc.) types
	 */
	public PrimitiveLine clone(){
		PrimitiveLine lineCopy = new PrimitiveLine(x1, y1, x2, y2);
		lineCopy.moveObject(posX, posY);
		lineCopy.color = color;
		
		return lineCopy;
	}
}
